package kr.hkit.powerjava.chapter25;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class ParseURLExample {
	public static void main(String[] args) {
		try {
			StringBuilder sb = new StringBuilder();
			
			URL url = new URL("http://hkit.kr/SUB/?ctId=49&eduCode=00000027:80");
			sb.append("protocol = " +url.getProtocol()+"\n");
			sb.append("authority = " + url.getAuthority()+"\n");
			sb.append("host = " + url.getHost()+"\n");
			sb.append("port = " + url.getPort()+"\n");
			sb.append("path = " + url.getPath()+"\n");
			sb.append("query = " + url.getQuery()+"\n");
			sb.append("file = " + url.getFile()+"\n");
			sb.append("ref = " + url.getRef()+"\n");
			System.out.println(sb);
	
			System.out.println("============================");
			
			BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
			String line;
			while((line = in.readLine()) != null) { //한줄씩 읽어옴 널이 되면 마지막임
				System.out.println(line);
			}
			in.close();
		} catch (MalformedURLException e) {
			System.err.println("잘못된 주소");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
		
		
		
		
		
	}
}